// Copyright 2021 Guoyoko. All Rights Reserved.

#include "SSWDetailPanelContainer.h"
#include "Property/SWCubeProperty.h"
#include "Property/SWSphereProperty.h"


void SSWDetailPanelContainer::Construct(const FArguments& InArgs)
{
	ChildSlot
		[
			SAssignNew(PropertyContentSlot, SBorder)
		];
}

void SSWDetailPanelContainer::Initialize()
{
	TSharedRef<SSWDetailPanelContainer> ContainerRef = StaticCastSharedRef<SSWDetailPanelContainer>(AsShared());
	TSharedPtr<FSWCubeProperty> CubePropertyPanel = MakeShareable(new FSWCubeProperty(ContainerRef));
	TSharedPtr<FSWSphereProperty> SpherePropertyPanel = MakeShareable(new FSWSphereProperty(ContainerRef));

	CubePropertyPanel->Initialize();
	SpherePropertyPanel->Initialize();

	AllPropertyPanels.Emplace(CubePropertyPanel);
	AllPropertyPanels.Emplace(SpherePropertyPanel);
}

void SSWDetailPanelContainer::CallBack_ActorSelected(AActor* InActor)
{

	PropertyContentSlot->SetContent(SNullWidget::NullWidget);
	if (InActor == nullptr)
	{
		return;
	}
	for (auto& PropertyPanel : AllPropertyPanels)
	{
		if (PropertyPanel->TryDisplayDetailPanel(InActor))
		{
			CurrentPropertyPanel = PropertyPanel;
			break;
		}
	}
}

void SSWDetailPanelContainer::SetPropertyPanel(TSharedRef<class SWidget> InPanel)
{
	PropertyContentSlot->SetContent(InPanel);
}

